<?
$sql = "select * from tb_member where id = '".$_GET['id']."'";
$qr = select($sql);
$rs = $qr[0];

if($_POST[action]=="save"){

	//insert data//
	$data = array(
	"username"=>$_POST['username'],
	"password"=>md5($_POST['password']),
	"name"=>$_POST['name'],
		"age"=>$_POST['age'],
		"work"=>$_POST['work'],
		"phone"=>$_POST['phone'],
		"email"=>$_POST['email'],
		"interest"=>$_POST['interest'],
		"times"=>$_POST['times'],
		"province"=>$_POST['province'],
		"income"=>$_POST['income'],
		"broker"=>$_POST['broker'],
		"know"=>$_POST['know'],
		"want"=>$_POST['want'],
		"car_type"=>$_POST['car_type'],
		"car_brand"=>$_POST['car_brand'],
		"car_insure"=>$_POST['car_type2'],
		"expire"=>$_POST['expire'],
		"comment"=>$_POST['comment'],
		"date_regis"=>date("Y-m-d")	
	);
	
	if(insert("tb_membership",$data))
	{
		delete("tb_member","id = '".$_POST[id]."'");
	}
	//end insert//
	//upload picture//
	if ($fileupload) {
		$array_last=explode(".",$fileupload_name);
		$c=count($array_last)-1; 
		$lastname=strtolower($array_last[$c]) ;
		$photoname=date("YmdHis")."_".mysql_insert_id().".".$lastname;
		$output = "../upload/product/$photoname";
		smart_resize_image($fileupload,337,195,true, $output,true,false);
		$data = array(
		"image"=>($photoname),
		);
		update("tb_product",$data,"id='".mysql_insert_id()."'");											
		unlink($fileupload);
	}//end if($fileupload)//
		
	//end upload//
	unset($_POST[action]);
	?>					
	<SCRIPT LANGUAGE="JavaScript">alert("add content suscessfully");window.location='admin.php?mode=member_list.php';</script>						
	<?
	exit();
}//end $_POST[action]//

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="15" align="left" class="headmenu"><img src="image/bar_left.gif" width="15" height="42" /></td>
    <td align="left" bgcolor="#434343" class="headmenu">เพิ่มสมาชิกเข้าสู่ระบบ</td>
    <td width="15" align="left" class="headmenu"><img src="image/bar_right.gif" width="15" height="42" /></td>
  </tr>
</table><br />
<script type="text/javascript">
//<![CDATA[
$(function(){

  $('#username1').keyup(function(e){
		var user = $.trim($(this).val());
		if (user.length > 0){
			$.ajax({
				url: 'test.php?test',
				type: 'POST',
				dataType: 'html',
				data: $(this).serialize(),
				success: function(data){
					if (data.indexOf('yes') != -1){
                                            $('#username-status').html('ชื่อผู้ใช้ซ้ำ');
					} else {
                                            $('#username-status').html('สามารถใช้งานได้');
					}
				}
			});
		}
		e.preventDefault();
	});

});
//]]>
</script>
<form action="admin.php?mode=member_add.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bordercolor="#999999" bgcolor="#ffffff">
    <tr>
      <td align="right" bgcolor="#FFFFFF" >ระบุรหัสสมาชิก :</td>
      <td bgcolor="#FFFFFF" class="style55"><label for="username"></label>
      <input type="text" name="username" id="username1" /> <span id="username-status" class="red13"></span></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" >ระบุรหัสผ่านสมาชิก :</td>
      <td bgcolor="#FFFFFF" class="style55"><label for="password"></label>
      <input type="text" name="password" id="password" /></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" >ผู้แนะนำ :</td>
      <td bgcolor="#FFFFFF" class="style55">
      	 <select name="ref_id2" id="ref_id2">
        <option selected="selected" value="0">---เพิ่มผู้รับผลประโยชน์---</option>
          <?php
	  	$sql = "select * from tb_membership where level = 4";
		$qr = select($sql);
		$total =count($qr);
		$i=0;
		while($i<$total)
		{
			$rs = $qr[$i];
			$i++;
	
	  ?>
          <option value="<?=$rs['id']?>">ชื่อ ::
            <?=$rs['name']?>
            รหัสสมาชิก ::
            <?=$rs['username']?>
            </option>
          <?php
		}
	  ?>
          </select>
      </td>
    </tr>
    <tr>
      <td width="439" bgcolor="#FFFFFF" ><div align="right" class="AR12BlackB">ชื่อ-นามสกุล : </div></td>
      <td width="442" bgcolor="#FFFFFF" class="style55"><?php echo $rs['name']; ?>
      <input type="hidden" name="name" id="name" value="<?php echo $rs['name']; ?>" /></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" ><div align="right" class="AR12BlackB">&nbsp;อายุ : </div></td>
      <td bgcolor="#FFFFFF"><?php echo $rs['age']; ?><span class="style55">
        <input name="age" type="hidden" id="age" value="<?php echo $rs['age']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" ><div align="right" class="AR12BlackB">&nbsp;&nbsp;อาชีพปัจจุบัน :</div></td>
      <td bgcolor="#FFFFFF" ><?php echo $rs['work'];?> <span class="style55">
        <input name="work" type="hidden" id="work" value="<?php echo $rs['work']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" ><div align="right" class="AR12BlackB">โทรศัพท์ : </div></td>
      <td bgcolor="#FFFFFF" ><?php echo $rs['phone']; ?><span class="style55">
        <input name="phone" type="hidden" id="phone" value="<?php echo $rs['phone']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td valign="top" bgcolor="#FFFFFF"><div align="right" class="AR12BlackB">Email : </div></td>
      <td bgcolor="#FFFFFF" ><?php echo $rs['email']; ?><span class="style55">
        <input name="email" type="hidden" id="email" value="<?php echo $rs['email']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" ><div align="right" class="AR12BlackB">ความต้องการของท่าน : </div></td>
      <td bgcolor="#FFFFFF"><?php echo $rs['interest']; ?><span class="style55">
        <input name="interest" type="hidden" id="interest" value="<?php echo $rs['interest']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" ><div align="right" class="AR12BlackB">เวลาสะดวก : </div></td>
      <td bgcolor="#FFFFFF" ><?php echo $rs['times'];?><span class="style55">
        <input name="times" type="hidden" id="times" value="<?php echo $rs['times']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" ><div align="right" class="AR12BlackB">จังหวัด : </div></td>
      <td bgcolor="#FFFFFF" ><?php echo $rs['province']; ?>
        <span class="style55">
        <input name="province" type="hidden" id="province" value="<?php echo $rs['province']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" ><div align="right" class="AR12BlackB">รายได้ต่อเดือนที่ต้องการ : </div></td>
      <td bgcolor="#FFFFFF" ><?php echo $rs['income']; ?><span class="style55">
        <input name="income" type="hidden" id="income" value="<?php echo $rs['income']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" class="AR12BlackB" >ปัจจุบันท่านมีใบอนุญาติประกันวินาศภัย :</td>
      <td valign="top" bgcolor="#FFFFFF" ><?php echo $rs['broker']; ?><span class="style55">
        <input name="broker" type="hidden" id="broker" value="<?php echo $rs['broker']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" class="AR12BlackB" >ท่านมีความรู้ด้านประกันภัยหรือเคยผ่านงานด้านประกันภัย :</td>
      <td valign="top" bgcolor="#FFFFFF" ><?php echo $rs['know']; ?><span class="style55">
        <input name="know" type="hidden" id="know" value="<?php echo $rs['know']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" class="AR12BlackB" >ท่านมีความสนใจในประกันภัย :</td>
      <td valign="top" bgcolor="#FFFFFF" class="AR12Black" ><?php echo $rs['want']; ?><span class="style55">
        <input name="want" type="hidden" id="want" value="<?php echo $rs['want']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" class="AR12BlackB" >ปัจจุบันท่านใช้รถยนต์ :</td>
      <td valign="top" bgcolor="#FFFFFF" class="AR12Black" ><?php echo $rs['car_type']; ?><span class="style55">
        <input name="car_type" type="hidden" id="car_type" value="<?php echo $rs['type']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" class="AR12BlackB" >ยี่ห้อ :</td>
      <td valign="top" bgcolor="#FFFFFF" class="AR12Black" ><?php echo $rs['car_brand']; ?><span class="style55">
        <input name="car_brand" type="hidden" id="car_brand" value="<?php echo $rs['car_brand']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" class="AR12BlackB" >กรณีท่านใช้รถยนต์ ท่านมีการทำประกัน :</td>
      <td valign="top" bgcolor="#FFFFFF" class="AR12Black" ><?php echo $rs['car_insure']; ?><span class="style55">
        <input name="car_insure" type="hidden" id="car_insure" value="<?php echo $rs['car_insure']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td align="right" bgcolor="#FFFFFF" class="AR12BlackB" >กรณีท่านใช้รถยนต์ รถของท่านหมดประกันวันที่ :</td>
      <td valign="top" bgcolor="#FFFFFF" class="AR12Black" ><?php echo $rs['expire'];?><span class="style55">
        <input name="expire" type="hidden" id="expire" value="<?php echo $rs['expire']; ?>" />
      </span></td>
    </tr>
    <tr>
      <td bgcolor="#FFFFFF" ><div align="right"><span class="AR12BlackB">ความต้องการอื่น ๆ:</span></div></td>
      <td bgcolor="#FFFFFF" ><?php echo $rs['comment']; ?><span class="style55">
        <input name="comment" type="hidden" id="comment" value="<?php echo $rs['coment']; ?>" />
      </span></td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td colspan="2" align="center" ><input type="submit" name="button" id="button" value="ยืนยันสมาชิก" />
      <input name="id" type="hidden" id="id" value="<?php echo $rs['id'] ?>" />
      <input name="action" type="hidden" id="action" value="save" /></td>
    </tr>
  </table>
</form>
</body>
</html>
